//
//  MyScroller.m
//  第九节作业
//
//  Created by dllo on 16/3/21.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "MyScroller.h"

@implementation MyScroller
#pragma mark - Creating and Init
- (instancetype)initWithFrame:(CGRect)frame withImages:(NSArray<UIImage *> *)images delegate:(id)delegate {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self configWithFrame:frame andImages:images delegate:delegate];
    }
    return self;
}

#pragma mark - config
- (void)configWithFrame:(CGRect)frame andImages:(NSArray *)images delegate:(id)delegate {
    
    
    // 设置contentSize
    self.contentSize = CGSizeMake(frame.size.width * images.count, frame.size.height);
    
    
    for (int i = 0; i < images.count; i++) {
        
        // 创建小的ScrollView
        UIScrollView *scrollViewOfSmall = [[UIScrollView alloc] initWithFrame:CGRectMake(frame.size.width * i, 0, frame.size.width, frame.size.height)];
        [self addSubview:scrollViewOfSmall];
        [scrollViewOfSmall release];
        
        scrollViewOfSmall.minimumZoomScale = 0.5;
        scrollViewOfSmall.maximumZoomScale = 2;
        scrollViewOfSmall.delegate = delegate;
        
        
        // 创建imageView子视图.
        UIImageView *imageView = [[UIImageView alloc] initWithImage:images[i]];
        
        imageView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
        
        [scrollViewOfSmall addSubview:imageView];
        [imageView release];
    }
    
    
    // 开启翻页效果.
    self.pagingEnabled = YES;
    
    // 边缘回弹效果
    self.bounces = YES;
    
    // 滑动指示器
    self.showsHorizontalScrollIndicator = YES;
    
}

@end
